package argo.hot100.dp;

public class Rob {


    public int rob(int[] nums) {

        int pre = 0;
        int cur = nums[0];

        for (int i = 2; i <= nums.length; i++) {
            int tmp = Math.max(cur, pre + nums[i - 1]);
            pre = cur;
            cur = tmp;
        }

        return cur;
    }


    public int robOld(int[] nums) {

        int res = 0;
        int[] dp = new int[nums.length + 1];

        dp[0] = 0;
        dp[1] = nums[0];

        for (int i = 2; i <= nums.length; i++) {
            dp[i] = Math.max(dp[i - 1], dp[i - 2] + nums[i - 1]);
        }

        return dp[nums.length];
    }
}
